package com.linkstec.service;

import java.util.List;

import javax.sql.DataSource;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson2.JSON;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.linkstec.mapper.UserMapper;
import com.linkstec.pojo.User;
@Service
public class UserServiceImpl /*implements UserService*/ implements InitializingBean{

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DataSource dynamicRoutingDataSource;

    private static final Logger logger = LogManager.getLogger();

//    @Override
    public List<User> getUser() throws Exception {
    	logger.info(JSON.toJSONString(userMapper.getUser()));
        return userMapper.getUser();
    }
    //根据id删除用户
//    @Override
    public void deleteUser(int id) throws Exception {
        userMapper.deleteUser(id);
    }
    //新增用户
//    @Override
    public void addUser(User user) throws Exception {
        userMapper.addUser(user);
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        DynamicRoutingDataSource aaa = (DynamicRoutingDataSource) dynamicRoutingDataSource;
        DruidDataSource bbb = aaa.getDataSource("db1").unwrap(DruidDataSource.class);
        System.out.println(bbb.getMaxActive());
        
    }
}